********************************
***Control Groups vs. No Audio***
********************************

clear all

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************

*Carolina's Computer*
if $carolina ==1  {
cap cd "~\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\"
}


if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/"
} 



*Robustness Versions*

*1. Base
global spec1covar0 		"$lasso0"
global spec1covar1 		"$lasso1"
global spec1restrict	""
global spec1out			"ln1_prob_index_"

*2. Vote
global spec2covar0 		"$lasso0"
global spec2covar1 		"$lasso1"
global spec2restrict	""
global spec2out			"ln1_prob_vote_"

*3. Charity
global spec3covar0 		"$lasso0"
global spec3covar1 		"$lasso1"
global spec3restrict	""
global spec3out			"ln1_prob_charity_"


	
*********************************
***Create Variables and Format***
*********************************
	
global lasso0 hispanic age55_64 candidate16_hillary candidate16_other ///
	immlevel_decrease gun_lessstrict abortion_illegal tax_toohigh health_notgvt ///
	occ_twitter occ_buzzfeed trumpfan lebronfan taylorfan bgatesfan ///
	obamafan obama_neutral topissue_health 
	
global lasso1 black hispanic age35_44 age45_54 hsdegree ///
	candidate16_hillary immlevel_decrease immlevel_same ///
	gun_same gun_lessstrict abortion_partlegal abortion_illegal tax_toohigh ///
	health_neutral health_notgvt i.freq_nytimes ///
	daily_tv occ_tv daily_newspaper i.freq_fox week_breitbart ///
	daily_breitbart occ_buzzfeed ///
	lebron_neutral obamafan trump_neutral trumpfan west topissue_tax 
	
global message1 "Anti"
global message2 "Anti"
global message3 "Pro"
global message4 "Pro"

global source1 "Trump"
global source2 "Obama"
global source3 "Trump"
global source4 "Obama" 

global party0 "Republicans"
global party1 "Democrats"
global var0 "ln(Probability Anti-Immigrant + 1)"
global var1 "ln(Probability Pro-Immigrant + 1)"
global dir0 "anti"
global dir1 "pro"

global color1 "blue"
global color0 "red"

global label1a0 "{bf:Anti}	"
global label2a0 "{bf:Anti}	"
global label3a0 "{bf:Pro}	"
global label4a0 "{bf:Pro}	"
global label1b0 "{bf:Trump}	"
global label2b0 "{bf:Obama}	"
global label3b0 "{bf:Trump}	"
global label4b0 "{bf:Obama}	"

foreach x in a b {
foreach y in 1 2 3 4 {
	global label`y'`x'1 ""
}
}

**************************************************
*CREATE PLOTS OF RESULTS*
**************************************************


use 3_clean_data, replace

gen group1=treatment==5 | treatment==7 | treatment==0
gen group2=treatment==6 | treatment==8 | treatment==0
gen group3=treatment==1 | treatment==3 | treatment==0
gen group4=treatment==2 | treatment==4 | treatment==0

gen president=treatment==1 | treatment==2 | treatment==5 | treatment==6
gen actor=treatment==3 | treatment==4 | treatment==7 | treatment==8
gen turkey= treatment==9 | treatment==10
gen priming=turkey==1 | president==1
gen message=actor==1 | president==1

**************************************************
*1. Density Charity Outcome*
**************************************************

sum prob_charity_anti if recruit==0 & treat==0
local repmean=round(r(mean)*10000)/10000
local repmean: di %6.3f `repmean'
sum prob_charity_anti if recruit==1 & treat==0
local demmean=round(r(mean)*10000)/10000
local demmean: di %6.3f `demmean'

# delimit ;
twoway (kdensity prob_charity_anti if recruit==0 & treat==0, lcolor(black) )
	(kdensity prob_charity_anti if recruit==1 & treat==0, lcolor(black) lpattern(dash_dot) )
	,
	ylabel(, nogrid) 
	ytitle("Density" " ")
	xtitle(" " "Scaled Charity Donation, {it:P(Anti)}" " ")
	legend(order(1 "Republicans" 2 "Democrats"))
	text(2 0.77 "Republican Mean =`repmean'", color(black))
	text(2 0.18 "Democrat Mean =`demmean'", color(black))
	graphregion(color(white)) 
;# delimit cr

graph export "$out/B13_DonationAnti_ByParty_Control.pdf", replace


**************************************************
*2. Charity Outcomes in Robustness Type Plots*
**************************************************


preserve

foreach m in "m" "ms" {
foreach p in 0 1 {
	gen b`m'`p'=.
	gen u`m'`p'=.
	gen l`m'`p'=.
}
}


gen n=_n

foreach p in 0 1 {

local n=0
	
foreach y in 4 3 2 1 {

foreach s in 3 2 1 {
	
	local n=`n'+1
 
	*Regression for Coefficients*
	reg ${spec`s'out}${dir`p'} message president ${spec`s'covar`p'} ///
		if (group`y'==1) & recruit==`p' ${spec`s'restrict}, robust
	
	*Anonymous Message - Beta_m*
	replace bm`p' = _b[message] if n==`n'
	replace um`p' = _b[message]+1.96*_se[message] if n==`n'
	replace lm`p' = _b[message]-1.96*_se[message] if n==`n'

	*Persuasion - Beta_ms *	
	replace bms`p' = _b[president] if n==`n'
	replace ums`p' = _b[president]+1.96*_se[president] if n==`n'
	replace lms`p' = _b[president]-1.96*_se[president] if n==`n'
	
	*Anonymous Message - P(Dist)*
	reg ${spec`s'out}${dir`p'} ${spec`s'covar`p'} ///
		if (group`y'==1 & president==0) & recruit==`p' ${spec`s'restrict}, robust
	predict res, res
	gen g=0 if actor==0 & e(sample)==1
	replace g=1 if actor==1 & e(sample)==1
	ksmirnov res if e(sample), by(g)
	local dm`n'`p'=round(r(p)*10000)/10000
	local dm`n'`p': di %6.3f `dm`n'`p''
	drop g res
	
	*Persuasion - P(Dist)*
	reg ${spec`s'out}${dir`p'} ${spec`s'covar`p'} ///
		if (group`y'==1 & treat!=0) & recruit==`p' ${spec`s'restrict}, robust
	predict res, res
	gen g=0 if president==0 & e(sample)==1
	replace g=1 if president==1 & e(sample)==1
	ksmirnov res if e(sample), by(g)
	local dms`n'`p'=round(r(p)*10000)/10000
	local dms`n'`p': di %6.3f `dms`n'`p''
	drop g res
	
	}
	
	local n=`n'+1
	
}


foreach m in "m" "ms" {

# delimit ;
twoway	
	(rcap l`m'`p' u`m'`p' n if n==3 | n==7 | n==11 | n==15 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==3 | n==7 | n==11 | n==15, mcolor(black) )	
	(rcap l`m'`p' u`m'`p' n if n==2 | n==6 | n==10 | n==14 , horizontal lcolor(black)) 
	(scatter n b`m'`p'  if n==2 | n==6 | n==10 | n==14, mcolor(black) msymbol(circle_hollow) )	
	(rcap l`m'`p' u`m'`p' n if n==1 | n==5 | n==9 | n==13 , horizontal lcolor(black)) 
	(scatter n b`m'`p' if n==1 | n==5 | n==9 | n==13 , mcolor(black) msymbol(square_hollow) )	
	, 
	xline(0, lcolor(black)) 
	ylabel(
	16	`" "{bf:P(Dist):}" "'
	15	`" "${label1a`p'}{it:`d`m'15`p''}" "'
	14	`" "${label1b`p'}{it:`d`m'14`p''}" "'
	13	`" "{it:`d`m'13`p''}" "'
	12	" "
	11	`" "${label2a`p'}{it:`d`m'11`p''}" "'
	10	`" "${label2b`p'}{it:`d`m'10`p''}" "'
	9	`" "{it:`d`m'9`p''}" "'
	8	" "
	7	`" "${label3a`p'}{it:`d`m'7`p''}" "'
	6	`" "${label3b`p'}{it:`d`m'6`p''}" "'
	5	`" "{it:`d`m'5`p''}" "'
	4	" "
	3	`" "${label4a`p'}{it:`d`m'3`p''}" "'
	2	`" "${label4b`p'}{it:`d`m'2`p''}" "'
	1	`" "{it:`d`m'1`p''}" "'
	, angle(0) labsize(small)) 
	xtitle(" " "{bf:${party`p'}}" "{it:${var`p'}}" " ")
	ytitle("")
	ylab(, nogrid)
	xlab(-.03(0.015).03)
	graphregion(color(white)) 
	legend(order(2 "Base - Index"  4 "Vote" 
	6 "Charity" ) rows(1)
	size(*0.75) symxsize(*0.4))
	ylabel(, tlength(0))
	saving("$out/`m'`p'.gph", replace)
	;
	# delimit cr

	}	
}
	
# delimit ;
grc1leg "$out/m0.gph" "$out/m1.gph", 
	ycommon xcommon legendfrom("$out/m0.gph")
	graphregion(color(white)) 
	imargin(-3 -8 -5 -6) scale(1.1) 
	;
# delimit cr
graph export "$out/B14_OutSample_AnonymousMessage.pdf", replace	


# delimit ;
grc1leg "$out/ms0.gph" "$out/ms1.gph", 
	ycommon xcommon legendfrom("$out/ms1.gph")
	graphregion(color(white)) 
	imargin(-3 -8 -5 -6) scale(1.1) 
	;
# delimit cr
graph export "$out/B14_OutSample_Persuasion.pdf", replace	

restore
